﻿@model CubicFWNet.Mvc.Areas.SystemManage.Models.ItemListViewModel

@{
    ViewBag.Title = "数据字典";
}
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        数据字典
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home", new { area = "" })">首页</a></li>
        <li class="active"><a href="@Url.Action("Index", "Item")">数据字典</a></li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-sm-3">
            <div class="box box-solid">
                <div class="box-body">
                    <div id="itemTree"></div>
                </div>
            </div>
        </div>
        <div class="col-sm-9">
            <div class="box box-solid">
                <div class="box-nav row clearfix" style="padding-bottom:0;">
                    <div class="col-sm-12 col-md-9" style="padding-bottom:10px;">
                        <button type="button" class="btn btn-primary" onclick="create();" title="新建"><i class="fa fa-plus-square"></i>&nbsp;新建</button>
                        <a class="btn btn-default" onclick="$.reload()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table class="footable table table-stripped table-bordered table-hover" id="footable">
                        <thead>
                            <tr>
                                <th>
                                    @Html.DisplayNameFor(model => model.Item.Name)
                                </th>
                                <th>
                                    @Html.DisplayNameFor(model => model.Item.SortNo)
                                </th>
                                <th data-hide="phone,tablet">
                                    @Html.DisplayNameFor(model => model.Item.CreateTime)
                                </th>
                                <th data-hide="phone,tablet">
                                    @Html.DisplayNameFor(model => model.Item.Memo)
                                </th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (null != Model.Items)
                            {
                                foreach (var item in Model.Items)
                                {
                                    <tr>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Name)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.SortNo)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.CreateTime)
                                        </td>

                                        <td>
                                            @Html.DisplayFor(modelItem => item.Memo)
                                        </td>
                                        <td>
                                            <button type="button" onclick="edit('@item.Id');" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i>编辑</button>
                                            <button type="button" onclick="del(this,'@item.Id');" class="btn  btn-xs btn-danger"><i class="fa fa-trash-o"></i>删除</button>
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<!--编辑对话框-->
<div class="modal" id="editDlg" style="display: none">
    @Html.Partial("_ItemForm", Model.Item)
</div>
<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">@Resources.Global.LoadingMsg</div>
</div>
@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            $('#footable').footable({ "sort": false });
            treeView();

            $('#editDlg').on("click", "#btnSubmit", function (event) {
                //event.preventDefault();
                var form = $("#frmedit");
                var postData = form.formSerialize();
                $.submitForm({
                    url: form.attr("action"),
                    param: postData,
                    success: function (data) {
                        //alert(data.Result);
                        $.reload();
                    },
                    error:function(data)
                    {
                        $('#editDlg').html(data.Result);       
                    }
                });
            });
        });

        function treeView() {
            $("#itemTree").treeview({
                url: "/Item/GetItemCategoryJson",
                onnodeclick: function (item) {
                    var itemId = $("#itemTree").getCurrentNode().id;
                    window.location.href = "/SystemManage/Item/Index/" + itemId;
                }
            });
            //设置wdtree的默认值
            $("#itemTree").setNodeChecked("@Model.CategoryItemId");
        }
        function create() {
            $("#frmedit").formInit("Id");
            $('#editDlg').modal();
        }
        function edit(id) {
            $.ajax({
                url: "/Item/GetFormJson",
                data: { ItemId: id },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#frmedit").formSerialize(data);
                    $("#editDlg").modal();
                }
            });
        }
        function del(obj, id) {
            $.deleteForm({
                url: "/Item/Delete",
                param: { id: id },
                success: function () {
                    $(obj).parents("tr").remove();
                }
            });
        }
    </script>
}
